interface KHTMLElement {
    /**
     * 插入到父元素
     * @param element 父元素
     * @description             element = HTMLElement  => 指定元素对象
     * @description             element = KHTMLElement => 指定元素对象
     * @returns 当前元素对象
     */
    insertTo(element: HTMLElement | KHTMLElement): KHTMLElement;
    /**
     * 插入到父元素
     * @param tagName 父元素名
     * @description             tagName = 'body'      => document.body
     * @description             tagName = 'head'      => document.head
     * @returns 当前元素对象
     */
    insertTo(tagName: 'body' | 'head'): KHTMLElement;
}
{
    Object.defineProperty(KHTMLElement.prototype, 'insertTo', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: U.F.overloading('DOM-insertTo',
            {
                types: [Etype.string],
                fn: function (this: KHTMLElement, tagName: string) {
                    const ele = this.ele();
                    if (!ele) { return this; }
                    if (tagName === 'body') { document.body.appendChild(ele); }
                    else if (tagName === 'head') { document.head.appendChild(ele); }
                    else { throw new IllegalArgumentError(); }
                    return this;
                }
            },
            {
                types: [Etype.HTMLElement],
                fn: function (this: KHTMLElement, element: HTMLElement) {
                    const ele = this.ele();
                    if (ele) { element.appendChild(ele); }
                    return this;
                }
            },
            {
                types: [Etype.KHTMLElement],
                fn: function (this: KHTMLElement, element: KHTMLElement) {
                    const ele = this.ele();
                    if (ele) {
                        const ele_parent = element.ele();
                        if (ele_parent) { ele_parent.appendChild(ele); }
                    }
                    return this;
                }
            },
        )
    });
}
